//
//  DJDiscoverViewController.m
//  WeiboDemo
//
//  Created by Bworm on 15/1/29.
//  Copyright (c) 2015年 Bworm. All rights reserved.
//

#import "DJDiscoverViewController.h"
#import "DJSearchBar.h"

@interface DJDiscoverViewController () <UITextFieldDelegate>

@property (nonatomic, weak) DJSearchBar *searchBar;
@end

@implementation DJDiscoverViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    DJSearchBar *searchBar = [[DJSearchBar alloc] init];
    searchBar.frame = CGRectMake(0, 0, 350, 30);
    self.navigationItem.titleView = searchBar;

//    UIButton *sb = [UIButton buttonWithType:UIButtonTypeCustom];
//    sb.imageView.image = [UIImage resizedImage:@"searchbar_background"];
//    sb.backgroundColor = [UIColor yellowColor];
//    self.navigationItem.titleView = sb;
//    sb.frame = self.navigationItem.titleView.frame;
//    sb.frame = CGRectMake(0, 0, 350, 30);
    
    searchBar.delegate = self;
    _searchBar = searchBar;
    
}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
//    UIViewController *newVc = [[UIViewController alloc] init];
//    [self.navigationController pushViewController:newVc animated:YES];
//    self.tabBarController.tabBar.hidden = YES;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"取消"
                                                                              style:UIBarButtonItemStylePlain
                                                                             target:self
                                                                             action:@selector(cancle)];
    self.searchBar.leftIconName = @"settings_statistic_triangle";
}


- (void)cancle
{
    self.navigationItem.rightBarButtonItem = nil;
    [[UIApplication sharedApplication].keyWindow endEditing:YES];
    self.searchBar.leftIconName = @"searchbar_searchlist_search_icon";
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [[UIApplication sharedApplication].keyWindow endEditing:YES];
}
@end
